var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2MyUtils = require("MyUtils");
var $2ADManager = require("ADManager");
var $2OppoConstant = require("OppoConstant");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var c = cc.Enum({
  Icon: 0,
  Banner: 1,
  Popup: 2,
  Special: 3
});
var def_OppoNative = /* */function (_cc$Component55) {
  babel_inherits(d, _cc$Component55);
  var _super60 = babel_createSuper(d);
  function d() {
    var _this132;
    babel_classCallCheck(this, d);
    _this132 = _super60.apply(this, arguments);
    _this132.nativideType = null;
    _this132.image = null;
    _this132.title = null;
    _this132.desc = null;
    _this132.wuchuPro = 0;
    return _this132;
  }
  babel_createClass(d, [{
    key: "getId",
    value: function getId() {
      var e;
      switch (this.nativideType) {
        case c.Icon:
          e = $2OppoConstant.default.POSID_NativeAD_InsertAD;
          break;
        case c.Banner:
          e = $2OppoConstant.default.POSID_NativeAD_Banner;
          break;
        case c.Popup:
          e = $2OppoConstant.default.POSID_NativeAD_InsertAD;
          break;
        case c.Special:
          e = $2OppoConstant.default.POSID_NativeAD_Banner;
      }
      console.log("this.nativideType:" + this.nativideType + " + ad_Id:" + e);
      return e;
    }
  }, {
    key: "onLoad",
    value: function onLoad() {
      var _this133 = this;
      if ($2ADManager.default.instance.sdkType != $2ADManager.SDK_TYPE.Oppo) {
        return void this.node.destroy();
      }
      if ($2ADManager.default.instance.isTest) {
        return;
      }
      var e;
      console.log("load=");
      this.createAD();
      switch (this.nativideType) {
        case c.Icon:
          e = 10;
          break;
        case c.Banner:
          e = $2OppoConstant.default.bannerRefresh;
          this.wuchuPro = $2OppoConstant.default.bannerWuchuPro;
          var _t35 = 0;
          this.schedule(function () {
            if (++_t35 == $2OppoConstant.default.autoBannerAD) {
              _t35 = 0;
              _this133.clickNativeAd();
            }
          });
          break;
        case c.Special:
          e = $2OppoConstant.default.bannerRefresh;
          this.wuchuPro = $2OppoConstant.default.bannerWuchuPro;
          break;
        case c.Popup:
          return void (this.wuchuPro = $2OppoConstant.default.popupWuchuPro);
      }
      this.schedule(function () {
        _this133.createAD();
      }, e);
    }
  }, {
    key: "start",
    value: function start() {
      if (this.nativideType == c.Banner) {
        console.log("y===", this.node.y);
        this.node.y = this.node.y * (cc.view.getCanvasSize().height / cc.view.getCanvasSize().width) / (1700 / 750);
        console.log("y2===", this.node.y);
      }
    }
  }, {
    key: "createAD",
    value: function createAD() {
      this.hideNode();
      $2ADManager.default.instance.isTest || this.creatNativeAD();
    }
  }, {
    key: "creatNativeAD",
    value: function creatNativeAD() {
      console.log("create====12");
      var e = this;
      this._native = qg.createNativeAd({
        adUnitId: this.getId()
      });
      this._native.offLoad();
      this._native.offError();
      if (this._native) {
        console.log("naitve===");
        this._native.onLoad(function (t) {
          e._nativeCurrentAdList = t.adList.pop();
          console.log("oppoNativeBanner icon: ", e._nativeCurrentAdList);
          e.showNativeAd();
        });
      }
      this._native.onError(function (t) {
        console.log("oppoNativeBanner： 原生广告加载失败，错误码：" + JSON.stringify(t));
        e.hideNode();
      });
      this._native.load();
    }
  }, {
    key: "showNativeAd",
    value: function showNativeAd() {
      var _this134 = this;
      var e;
      e = this._nativeCurrentAdList.iconUrlList[0];
      if (!e) {
        e = this._nativeCurrentAdList.imgUrlList[0];
      }
      if (this.nativideType != c.Icon) {
        this.title.string = this._nativeCurrentAdList.title;
        this.desc.string = this._nativeCurrentAdList.desc;
      }
      console.log("imgUrl", e);
      var t = ".png";
      -1 != e.indexOf(".jpg") && (t = ".jpg");
      if (e) {
        cc.assetManager.loadRemote(e, {
          ext: t
        }, function (e, t) {
          if (e) {
            console.log("err==", e);
            return void _this134.hideNode();
          }
          var a = new cc.SpriteFrame(t);
          _this134.image.spriteFrame = a;
          console.log("adid==", _this134._nativeCurrentAdList.adId);
          _this134._native.reportAdShow({
            adId: _this134._nativeCurrentAdList.adId
          });
          _this134.showNode();
        });
      } else {
        this.hideNode();
      }
    }
  }, {
    key: "clickNativeAd",
    value: function clickNativeAd() {
      console.log("clickad==");
      this._native && 0 != this.node.opacity && this._nativeCurrentAdList && this._native.reportAdClick({
        adId: this._nativeCurrentAdList.adId
      });
    }
  }, {
    key: "onClickWuchu",
    value: function onClickWuchu() {
      if ($2ADManager.default.instance.sdkType == $2ADManager.SDK_TYPE.Oppo && $2MyUtils.MyUtils.probability(this.wuchuPro)) {
        console.log("wuchu====");
        this.clickNativeAd();
      }
    }
  }, {
    key: "onClickWuchu2",
    value: function onClickWuchu2(e, t) {
      if ($2ADManager.default.instance.sdkType != $2ADManager.SDK_TYPE.Oppo) {
        return;
      }
      var a;
      switch (t) {
        case 0:
          a = $2OppoConstant.default.btnWuchuPro;
          break;
        case 1:
          a = $2OppoConstant.default.btnWuchuPro2;
          break;
        case 2:
          a = $2OppoConstant.default.btnWuchuPro3;
          break;
        default:
          a = 0;
      }
      $2MyUtils.MyUtils.probability(a) && this.clickNativeAd();
    }
  }, {
    key: "showNode",
    value: function showNode() {
      this.node.opacity = 255;
    }
  }, {
    key: "hideNode",
    value: function hideNode() {
      this.node.opacity = 0;
    }
  }]);
  return d;
}(cc.Component);
cc__decorate([ccp_property({
  type: cc.Enum(c)
})], def_OppoNative.prototype, "nativideType", undefined);
cc__decorate([ccp_property(cc.Sprite)], def_OppoNative.prototype, "image", undefined);
cc__decorate([ccp_property(cc.Label)], def_OppoNative.prototype, "title", undefined);
cc__decorate([ccp_property(cc.Label)], def_OppoNative.prototype, "desc", undefined);
def_OppoNative = cc__decorate([ccp_ccclass], def_OppoNative);
exports.default = def_OppoNative;